#include "widget.h"
#include "ui_widget.h"
#include <QDateTimeEdit>
#include <QDateTime>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QDateTime told = ui->dateTimeEdit_old->dateTime();
    QDateTime tnew = ui->dateTimeEdit_new->dateTime();
    // daysTo计算天数时不满24小时会进1，算成1天
    // 正确的天数我们得用秒去算
    int days = told.daysTo(tnew);
    int seconds = told.secsTo(tnew);
    int days2 = (seconds / 3600) / 24;
    int sec = (seconds / 3600) % 24;
    qDebug() << days << " " << seconds << endl;
    qDebug() << days2 << " " << sec << endl;
    ui->label->setText("时间差为" + QString::number(days) + "天零" + QString::number(sec) + "小时");
}
